import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Random;

public class Insert implements Runnable {
    static double totalTime;
    static TestDAO testDAO = new TestDAO();
    static Random random = new Random();

    @Override
    public void run() {
        for (int i = 0; i < 1000000; i++) {
            String id = RandomUtil.generateByRandom(11);
            String password = "123456";
            int points = random.nextInt(1000000);
            Customer customer = new Customer(id, password, points);
            double startTime = System.nanoTime();
            testDAO.addCustomer(customer);
            double endTime = System.nanoTime();
            totalTime = endTime - startTime;
            try {
                String insertTableFileName = "src/insert.txt";
                File insertTableFile = new File(insertTableFileName);
                FileWriter fileWriter = new FileWriter(insertTableFile, true);
                BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
                bufferedWriter.write(String.valueOf(totalTime / 1000000) + "\n");
                bufferedWriter.close();
                fileWriter.close();
                System.out.println("插入操作" + String.valueOf(totalTime / 1000000) + "ms");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
